package com.wwmz.pattern.prototype.job;

import java.util.ArrayList;

/**
 * Created by wumz on 2020/9/17 17:31
 */
public class JsonTest {
    public static void main(String[] args) {
        //创建原型对象
        JsonPrototype jsonPrototype = new JsonPrototype();
        jsonPrototype.setSex("男");
        jsonPrototype.setName("wumz");
        jsonPrototype.setHobbies(new ArrayList<String>(){{add("打球");add("吃饭");}});
        System.out.println("原型对象"+jsonPrototype);
        //拷贝
        JsonPrototype clone = jsonPrototype.deepCloneHobbies();
        clone.getHobbies().add("游泳");
        System.out.println("克隆对象"+clone);
        System.out.println(clone == jsonPrototype);
        System.out.println("原型爱好："+jsonPrototype.getHobbies());
        System.out.println("克隆爱好："+clone.getHobbies());
        System.out.println(clone.getHobbies() == jsonPrototype.getHobbies());
    }
}
